Package-level declarations

Types

Link copied to clipboard
class AbortController(logger: Logger = NoopLogger)

Mutable abort source — the v6 equivalent of AbortController. Hold the controller, hand the signal to the agent, call abort from the UI's stop button.

Link copied to clipboard
class AbortError(message: String = "operation aborted") : CancellationException

Thrown from AbortSignal.throwIfAborted when the signal has fired.

Link copied to clipboard
interface AbortSignal
Link copied to clipboard

Member-extensions converting coroutine handles into AbortSignals.

Link copied to clipboard
interface Agent<TContext, TOutput>
Link copied to clipboard
sealed class AgentError : AiSdkException
Link copied to clipboard
sealed class AgentEvent
Link copied to clipboard
class AgentSession<TContext, TOutput>(scope: CoroutineScope, agent: Agent<TContext, TOutput>, initialMessages: List<ModelMessage> = emptyList())
Link copied to clipboard
Link copied to clipboard
data class AgentSessionState<TOutput>(val messages: List<ModelMessage> = emptyList(), val status: AgentSessionStatus = AgentSessionStatus.Ready, val text: String = "", val output: TOutput? = null, val pendingApprovals: List<PendingApproval> = emptyList(), val lastResult: GenerateResult<TOutput>? = null, val error: Throwable? = null)
Link copied to clipboard

Returned from prepareCall. Any non-null field overrides the agent default for this invocation only.

Link copied to clipboard
Link copied to clipboard
annotation class AiSdkDsl

Marks AI SDK builder receivers so nested DSL blocks do not leak outer scopes.

Link copied to clipboard
Link copied to clipboard
class APICallError(message: String, val url: String, val requestBodyValues: JsonElement? = null, val statusCode: Int? = null, val responseHeaders: Map<String, String>? = null, val responseBody: String? = null, cause: Throwable? = null, val isRetryable: Boolean = statusCode == 408 || statusCode == 409 || statusCode == 429 || (statusCode ?: 0) >= 500) : AiSdkException

Provider HTTP/API failure with normalized request and response details.

Link copied to clipboard
Link copied to clipboard

Approval-identity helpers for PendingApproval.

Link copied to clipboard
data class AudioSource(val mediaType: String, val base64: String, val filename: String? = null)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class AuthorizationServerMetadata(val issuer: String? = null, val authorizationEndpoint: String? = null, val tokenEndpoint: String? = null, val registrationEndpoint: String? = null, val responseTypesSupported: List<String>? = null, val grantTypesSupported: List<String>? = null, val tokenEndpointAuthMethodsSupported: List<String>? = null, val codeChallengeMethodsSupported: List<String>? = null)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class CallTimeoutError(val timeout: Duration, message: String = "Call timed out after ") : AiSdkException
Link copied to clipboard
class CallToolResult(val content: List<JsonObject> = emptyList(), val structuredContent: JsonElement? = null, val isError: Boolean = false, val toolResult: JsonElement? = null, val meta: JsonObject? = null)
Link copied to clipboard
class CallWarning(val type: String, val message: String? = null, val details: JsonElement? = null)

Provider warning for a call that still completed. Mirrors v6's CallWarning shape without baking provider-specific warning enums into common code.

Link copied to clipboard
sealed class ChunkBy
Link copied to clipboard
class ClientAuthResult(val additionalHeaders: Map<String, String> = emptyMap(), val additionalParams: Map<String, String> = emptyMap())
Link copied to clipboard
class Completion(options: UseCompletionOptions = UseCompletionOptions(block = {}))
Link copied to clipboard
Link copied to clipboard
sealed class CompletionPhase
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
data class CompletionState(val input: String = "", val phase: CompletionPhase = CompletionPhase.Idle)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Content part of a ModelMessage. Sealed so consumers exhaust over variants — adding a new content type forces a compile error at every dispatch site.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
data class DataUrl(val mediaType: String, val base64: String)
Link copied to clipboard
class DeepPartial<T>(val value: T?)
Link copied to clipboard
Link copied to clipboard
class DefaultRedactor(options: RedactionOptions = RedactionOptions {}) : Redactor
Link copied to clipboard
Link copied to clipboard
class DevToolsStep(val id: String, val runId: String, val stepNumber: Int, val type: String, val modelId: String, val provider: String, val input: JsonElement, val providerOptions: ProviderOptions)
Link copied to clipboard
class DevToolsStepResult(val durationMs: Long, val output: JsonElement?, val usage: Usage?, val error: String?, val rawRequest: JsonElement? = null, val rawResponse: JsonElement? = null, val rawChunks: List<JsonElement> = emptyList())
Link copied to clipboard
class DownloadedAsset(val base64: String, val mediaType: String?)

The base64 bytes + media type of a downloaded asset.

Link copied to clipboard
class DownloadError(val url: String, message: String, val statusCode: Int? = null, val statusText: String? = null, cause: Throwable? = null) : AiSdkException
Link copied to clipboard
typealias DownloadFunction = suspend (url: String) -> DownloadedAsset

Downloads a remote asset for PromptConversion.convertToLanguageModelPrompt.

Link copied to clipboard
data class ElicitationRequest(val params: ElicitationRequestParams, val method: String = "elicitation/create")
Link copied to clipboard
data class ElicitationRequestParams(val message: String, val requestedSchema: JsonElement, val meta: JsonObject? = null)
Link copied to clipboard
Link copied to clipboard
class ElicitResult(val action: String, val content: JsonObject? = null, val meta: JsonObject? = null)
Link copied to clipboard
Link copied to clipboard
object Embedding
Link copied to clipboard
Link copied to clipboard
interface EmbeddingModel
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class EmbeddingModelResult(val embeddings: List<List<Float>>, val usage: EmbeddingUsage = EmbeddingUsage(), val warnings: List<CallWarning> = emptyList(), val request: LanguageModelRequestMetadata = LanguageModelRequestMetadata(), val response: LanguageModelResponseMetadata = LanguageModelResponseMetadata(), val providerMetadata: ProviderMetadata = ProviderMetadata.None)
Link copied to clipboard
class EmbeddingUsage(val tokens: Int = 0, val raw: JsonElement? = null)
Link copied to clipboard
class EmbedManyResult<TValue>(val values: List<TValue>, val embeddings: List<List<Float>>, val usage: EmbeddingUsage, val warnings: List<CallWarning> = emptyList(), val request: LanguageModelRequestMetadata = LanguageModelRequestMetadata(), val response: LanguageModelResponseMetadata = LanguageModelResponseMetadata(), val responses: List<LanguageModelResponseMetadata> = emptyList(), val providerMetadata: ProviderMetadata = ProviderMetadata.None)
Link copied to clipboard
class EmbedResult<TValue>(val value: TValue, val embedding: List<Float>, val usage: EmbeddingUsage, val warnings: List<CallWarning> = emptyList(), val request: LanguageModelRequestMetadata = LanguageModelRequestMetadata(), val response: LanguageModelResponseMetadata = LanguageModelResponseMetadata(), val providerMetadata: ProviderMetadata = ProviderMetadata.None)
Link copied to clipboard
class EmptyResponseBodyError(message: String = "Empty response body") : AiSdkException
Link copied to clipboard
sealed class ExecuteToolResult<out TOutput>
Link copied to clipboard
Link copied to clipboard
class Experimental_StdioMCPTransport(val config: StdioConfig, engineContext: CoroutineContext = Dispatchers.Default) : MCPTransport
Link copied to clipboard
@RequiresOptIn(level = RequiresOptIn.Level.ERROR, message = "This is an experimental AI SDK API. It may change or be removed without notice. Opt in with @OptIn(ExperimentalAiSdkApi::class).")
annotation class ExperimentalAiSdkApi

Marks a declaration as experimental: a surface whose shape may change or be removed in any release without going through the normal deprecation cycle.

Link copied to clipboard
sealed class FileData
Link copied to clipboard

Why a generation step ended.

Link copied to clipboard
class GatewayAuthenticationError(message: String = "Authentication failed", statusCode: Int = 401, generationId: String? = null, cause: Throwable? = null) : GatewayError
Link copied to clipboard
Link copied to clipboard
data class GatewayAuthToken(val token: String, val authMethod: GatewayAuthMethod)
Link copied to clipboard
class GatewayCreditsResponse(val balance: String, val totalUsed: String)
Link copied to clipboard
open class GatewayError(message: String, val statusCode: Int = 500, val type: String = "gateway_error", val generationId: String? = null, cause: Throwable? = null, val isRetryable: Boolean = statusCode == 408 || statusCode == 409 || statusCode == 429 || statusCode >= 500) : AiSdkException
Link copied to clipboard
class GatewayGenerationInfo(val id: String, val totalCost: Double, val upstreamInferenceCost: Double, val usage: Double, val createdAt: String, val model: String, val isByok: Boolean, val providerName: String, val streamed: Boolean, val finishReason: String, val latency: Int, val generationTime: Int, val promptTokens: Int, val completionTokens: Int, val reasoningTokens: Int, val cachedTokens: Int, val cacheCreationTokens: Int, val billableWebSearchCalls: Int)
Link copied to clipboard
class GatewayInternalServerError(message: String = "Internal server error", statusCode: Int = 500, generationId: String? = null, cause: Throwable? = null) : GatewayError
Link copied to clipboard
class GatewayInvalidRequestError(message: String = "Invalid request", statusCode: Int = 400, generationId: String? = null, cause: Throwable? = null) : GatewayError
Link copied to clipboard
class GatewayLanguageModelEntry(val id: String, val name: String, val description: String? = null, val pricing: GatewayPricing? = null, val specification: GatewayLanguageModelSpecification, val modelType: GatewayModelType? = null)
Link copied to clipboard
class GatewayLanguageModelSpecification(val specificationVersion: String = "v3", val provider: String, val modelId: String)
Link copied to clipboard
Link copied to clipboard
class GatewayModelNotFoundError(message: String = "Model not found", statusCode: Int = 404, val modelId: String? = null, generationId: String? = null, cause: Throwable? = null) : GatewayError
Link copied to clipboard
Link copied to clipboard
class GatewayPricing(val input: String, val output: String, val cachedInputTokens: String? = null, val cacheCreationInputTokens: String? = null)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class GatewayRateLimitError(message: String = "Rate limit exceeded", statusCode: Int = 429, generationId: String? = null, cause: Throwable? = null) : GatewayError
Link copied to clipboard
class GatewayRequestContext(val baseUrl: String, val headers: Map<String, String>)
Link copied to clipboard
class GatewayResponseError(message: String = "Invalid response from Gateway", statusCode: Int = 502, val response: JsonElement? = null, generationId: String? = null, cause: Throwable? = null) : GatewayError
Link copied to clipboard
Link copied to clipboard
class GatewaySpendReportRow(val day: String? = null, val hour: String? = null, val user: String? = null, val model: String? = null, val tag: String? = null, val provider: String? = null, val credentialType: GatewayCredentialType? = null, val totalCost: Double, val marketCost: Double? = null, val inputTokens: Int? = null, val outputTokens: Int? = null, val cachedInputTokens: Int? = null, val cacheCreationInputTokens: Int? = null, val reasoningTokens: Int? = null, val requestCount: Int? = null)
Link copied to clipboard
class GatewayTimeoutError(message: String = "Gateway request timed out", statusCode: Int = 408, generationId: String? = null, cause: Throwable? = null) : GatewayError
Link copied to clipboard
class GatewayTools(val parallelSearch: Tool<JsonElement, JsonElement, Any?> = ProviderExecutedTool( name = "parallelSearch", description = "Search the web using Parallel AI's Search API for LLM-optimized excerpts.", inputSerializer = JsonElement.serializer(), outputSerializer = JsonElement.serializer(), ), val perplexitySearch: Tool<JsonElement, JsonElement, Any?> = ProviderExecutedTool( name = "perplexitySearch", description = "Search the web using Perplexity's Search API for real-time information.", inputSerializer = JsonElement.serializer(), outputSerializer = JsonElement.serializer(), ))
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class GeneratedFile(val mediaType: String, val base64: String, val filename: String? = null, val providerMetadata: ProviderMetadata = ProviderMetadata.None, val url: String? = null)
Link copied to clipboard

GeneratedFile read accessors as member-extensions. Use via member-import (import ai.torad.aisdk.GeneratedFiles.bytes) or with(GeneratedFiles) { ... }.

Link copied to clipboard
class GenerateImageResult(val images: List<GeneratedFile>, val warnings: List<CallWarning> = emptyList(), val response: LanguageModelResponseMetadata = LanguageModelResponseMetadata(), val providerMetadata: ProviderMetadata = ProviderMetadata.None, val responses: List<LanguageModelResponseMetadata> = listOf(response), val usage: ImageModelUsage = ImageModelUsage())
Link copied to clipboard
class GenerateObjectResult<TOutput>(val value: TOutput, val text: String, val reasoning: String? = null, val finishReason: FinishReason, val usage: Usage, val warnings: List<CallWarning> = emptyList(), val request: LanguageModelRequestMetadata = LanguageModelRequestMetadata(), val response: LanguageModelResponseMetadata = LanguageModelResponseMetadata(), val providerMetadata: ProviderMetadata = ProviderMetadata.None)
Link copied to clipboard

Final output of Agent.generate. When pendingApprovals is non-empty, the loop paused on tool approval — call Agent.generate again with messages plus tool-approval-response messages to resume.

Link copied to clipboard
class GenerateSpeechResult(val audio: GeneratedFile, val warnings: List<CallWarning> = emptyList(), val response: LanguageModelResponseMetadata = LanguageModelResponseMetadata(), val providerMetadata: ProviderMetadata = ProviderMetadata.None, val responses: List<LanguageModelResponseMetadata> = listOf(response))
Link copied to clipboard
Link copied to clipboard
class GenerateVideoResult(val videos: List<GeneratedFile>, val warnings: List<CallWarning> = emptyList(), val response: LanguageModelResponseMetadata = LanguageModelResponseMetadata(), val providerMetadata: ProviderMetadata = ProviderMetadata.None, val responses: List<LanguageModelResponseMetadata> = listOf(response))
Link copied to clipboard
sealed class GenerationInput

Prompt material accepted by high-level generators.

Link copied to clipboard
class GetPromptResult(val messages: List<MCPPromptMessage>, val description: String? = null, val meta: JsonObject? = null)
Link copied to clipboard
class HttpMCPTransport(client: HttpClient, url: String, headers: Map<String, String> = emptyMap(), authProvider: OAuthClientProvider? = null, engineContext: CoroutineContext = Dispatchers.Default, reconnectionOptions: MCPReconnectionOptions = MCPReconnectionOptions {}) : MCPTransport
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class ImageGenerationFile(val mediaType: String? = null, val base64: String? = null, val url: String? = null, val filename: String? = null)
Link copied to clipboard
Link copied to clipboard
class ImageMiddlewareCallContext(val params: ImageGenerationParams, val model: ImageModel, val doGenerate: suspend (ImageGenerationParams) -> ImageModelResult)
Link copied to clipboard
interface ImageModel
Link copied to clipboard
Link copied to clipboard
class ImageModelResult(val images: List<GeneratedFile>, val warnings: List<CallWarning> = emptyList(), val response: LanguageModelResponseMetadata = LanguageModelResponseMetadata(), val providerMetadata: ProviderMetadata = ProviderMetadata.None, val usage: ImageModelUsage = ImageModelUsage())
Link copied to clipboard
class ImageModelUsage(val inputTokens: Int? = null, val outputTokens: Int? = null, val totalTokens: Int? = null)

Token usage reported by an image model, when available. Mirrors v6's ImageModelUsage.

Link copied to clipboard
class InitializeResult(val protocolVersion: String, val capabilities: MCPServerCapabilities = MCPServerCapabilities(), val serverInfo: Configuration, val instructions: String? = null, val meta: JsonObject? = null)
Link copied to clipboard
@RequiresOptIn(level = RequiresOptIn.Level.ERROR, message = "This is an internal AI SDK API and is not part of the public contract. It may change or be removed without notice. Opt in with @OptIn(InternalAiSdkApi::class).")
annotation class InternalAiSdkApi

Marks a declaration as internal to the AI SDK implementation: visible across module boundaries for technical reasons (KMP source sets, inlining), but not part of the supported public contract. It may change or be removed at any time.

Link copied to clipboard
class InvalidArgumentError(val argument: String, reason: String, cause: Throwable? = null) : AiSdkException
Link copied to clipboard
class InvalidDataContentError(val content: String?, cause: Throwable? = null, message: String = "Invalid data content. Expected a base64 string, ByteArray, or platform byte buffer, " + "but got ${content ?: "null"}.") : AiSdkException
Link copied to clipboard
class InvalidMessageRoleError(val role: String, message: String = "Invalid message role: '") : AiSdkException
Link copied to clipboard
class InvalidPromptError(val prompt: String?, message: String, cause: Throwable? = null) : AiSdkException
Link copied to clipboard
class InvalidResponseDataError(val data: JsonElement?, message: String = "Invalid response data: ") : AiSdkException
Link copied to clipboard
class InvalidStreamPartError(val chunk: String?, message: String) : AiSdkException
Link copied to clipboard
Link copied to clipboard
class InvalidToolInputError(val toolInput: String, val toolName: String, cause: Throwable, message: String = "Invalid input for tool ") : AiSdkException
Link copied to clipboard

JSON-mode instruction injection operations.

Link copied to clipboard
class JSONParseError(val text: String, cause: Throwable) : AiSdkException
Link copied to clipboard
data class JSONRPCError(val id: JsonElement, val error: JSONRPCErrorData, val jsonrpc: String = JSONRPC_VERSION) : JSONRPCMessage
Link copied to clipboard
data class JSONRPCErrorData(val code: Int, val message: String, val data: JsonElement? = null)
Link copied to clipboard
sealed interface JSONRPCMessage
Link copied to clipboard
data class JSONRPCNotification(val method: String, val params: JsonObject? = null, val jsonrpc: String = JSONRPC_VERSION) : JSONRPCMessage
Link copied to clipboard
data class JSONRPCRequest(val id: JsonElement, val method: String, val params: JsonObject? = null, val jsonrpc: String = JSONRPC_VERSION) : JSONRPCMessage
Link copied to clipboard
data class JSONRPCResponse(val id: JsonElement, val result: JsonElement? = JsonObject(emptyMap()), val jsonrpc: String = JSONRPC_VERSION) : JSONRPCMessage
Link copied to clipboard
class KtorGatewayTransport(client: HttpClient, json: Json = aiSdkJson) : GatewayTransport
Link copied to clipboard
interface LanguageModel
Link copied to clipboard

Single parameter envelope for both generate and stream so middleware can wrap both the same way and wrapLanguageModel only needs one pass-through shape.

Link copied to clipboard
Link copied to clipboard
class LanguageModelRequestMetadata(val body: JsonElement? = null)

Request metadata recorded by HTTP-backed or gateway providers.

Link copied to clipboard
class LanguageModelResponseMetadata(val id: String? = null, val timestampMillis: Long? = null, val modelId: String? = null, val headers: Map<String, String> = emptyMap(), val body: JsonElement? = null)

Response metadata recorded by HTTP-backed or gateway providers.

Link copied to clipboard
class LanguageModelResult(val text: String, val toolCalls: List<ContentPart.ToolCall> = emptyList(), val finishReason: FinishReason, val usage: Usage, val providerMetadata: ProviderMetadata = ProviderMetadata.None, val content: List<ContentPart> = buildList { if (text.isNotEmpty()) add(ContentPart.Text(text)) addAll(toolCalls) }, val rawFinishReason: String? = null, val warnings: List<CallWarning> = emptyList(), val request: LanguageModelRequestMetadata = LanguageModelRequestMetadata(), val response: LanguageModelResponseMetadata = LanguageModelResponseMetadata())

One-shot generate result.

Link copied to clipboard
class LanguageModelStreamResult(val stream: Flow<StreamEvent>, val request: LanguageModelRequestMetadata = LanguageModelRequestMetadata(), val response: LanguageModelResponseMetadata = LanguageModelResponseMetadata())

Provider stream plus request/response metadata known before collection.

Link copied to clipboard
class LanguageModelTool(val name: String, val description: String, val parametersSchemaJson: String, val providerExecuted: Boolean = false, val metadata: Map<String, JsonElement> = emptyMap(), val strict: Boolean? = null, val providerOptions: ProviderOptions = ProviderOptions.None)

Tool advertisement at the model surface — the JSON-schema shape the provider needs. Distinct from the application-side Tool which carries a Kotlin executor; this is the wire shape that crosses into a provider.

Link copied to clipboard
class LazySchema<T>(createSchema: () -> Schema<T>)
Link copied to clipboard
class ListPromptsResult(val prompts: List<MCPPrompt>, val nextCursor: String? = null, val meta: JsonObject? = null)
Link copied to clipboard
class ListResourcesResult(val resources: List<MCPResource>, val nextCursor: String? = null, val meta: JsonObject? = null)
Link copied to clipboard
class ListResourceTemplatesResult(val resourceTemplates: List<MCPResourceTemplate>, val nextCursor: String? = null, val meta: JsonObject? = null)
Link copied to clipboard
class ListToolsResult(val tools: List<MCPToolDefinition>, val nextCursor: String? = null, val meta: JsonObject? = null)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
interface Logger
Link copied to clipboard
class LoopState(val stepNumber: Int, val totalSteps: Int, val lastFinishReason: FinishReason, val toolCallsThisStep: List<ContentPart.ToolCall>, val toolCallsAllSteps: List<ContentPart.ToolCall>, val steps: List<StepResult> = emptyList())
Link copied to clipboard

Loop-termination checks for the tool loop.

Link copied to clipboard
@RequiresOptIn(level = RequiresOptIn.Level.ERROR, message = "Direct LanguageModel execution is a low-level provider API. Use Agent.generate/Agent.stream or a high-level SDK API for application prompts, or opt in with @OptIn(LowLevelLanguageModelApi::class).")
annotation class LowLevelLanguageModelApi

Marks direct LanguageModel execution as low-level provider access.

Link copied to clipboard
data class MCPBaseParams(val meta: JsonObject? = null)
Link copied to clipboard
interface MCPClient
Link copied to clipboard
class MCPClientCapabilities(val elicitation: ElicitationCapability? = null, val experimental: JsonObject? = null)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class MCPClientError(message: String, val code: Int? = null, val data: JsonElement? = null, cause: Throwable? = null) : AiSdkException
Link copied to clipboard
class MCPPrompt(val name: String, val title: String? = null, val description: String? = null, val arguments: List<MCPPromptArgument>? = null)
Link copied to clipboard
class MCPPromptArgument(val name: String, val description: String? = null, val required: Boolean? = null)
Link copied to clipboard
class MCPPromptMessage(val role: String, val content: JsonObject)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class MCPResource(val uri: String, val name: String, val title: String? = null, val description: String? = null, val mimeType: String? = null, val size: Long? = null)
Link copied to clipboard
class MCPResourceTemplate(val uriTemplate: String, val name: String, val title: String? = null, val description: String? = null, val mimeType: String? = null)
Link copied to clipboard
class MCPServerCapabilities(val experimental: JsonObject? = null, val logging: JsonObject? = null, val prompts: JsonObject? = null, val resources: JsonObject? = null, val tools: JsonObject? = null, val elicitation: ElicitationCapability? = null)
Link copied to clipboard
class MCPToolDefinition(val name: String, val title: String? = null, val description: String? = null, val inputSchema: JsonObject = JsonObject(mapOf("type" to JsonPrimitive("object"))), val outputSchema: JsonObject? = null, val annotations: JsonObject? = null, val meta: JsonObject? = null)
Link copied to clipboard
class MCPToolSchema(val inputSchema: JsonElement, val outputSchema: JsonElement? = null)
Link copied to clipboard
Link copied to clipboard
interface MCPTransport

Transport interface for MCP communication. Implementations may wrap stdio, Streamable HTTP, SSE, WebSockets, or a test fixture.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class MessageConversionError(val originalMessage: String?, message: String) : AiSdkException
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

What a middleware receives. Contains:

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
value class ModelId(val value: String)
Link copied to clipboard

Factory helpers for the value-class identifiers. These cannot be expressed as PascalCase faux-constructors because a same-signature fun ProviderId(String) / fun ModelId(String) would conflict with the value-class primary constructors, so they live as members of this object.

Link copied to clipboard
class ModelMessage(val role: MessageRole, val content: List<ContentPart>)

v6 wire-shape message — the type passed to LanguageModel generations. Renamed from CoreMessage (v5) per the AI SDK v6 migration.

Link copied to clipboard
data class ModelRef(val modelId: ModelId, val providerId: ProviderId? = null)
Link copied to clipboard
class MutableTelemetrySpan(val name: String, initialAttributes: Map<String, JsonElement> = emptyMap()) : TelemetryActiveSpan
Link copied to clipboard
class NoContentGeneratedError(message: String = "No content generated.") : AiSdkException
Link copied to clipboard
class NoImageGeneratedError(message: String = "No image generated", val responses: List<LanguageModelResponseMetadata> = emptyList(), cause: Throwable? = null) : AiSdkException
Link copied to clipboard
class NoObjectGeneratedError(message: String = "No object generated", val text: String? = null, val response: LanguageModelResponseMetadata? = null, val usage: Usage? = null, val finishReason: FinishReason? = null, cause: Throwable? = null) : AiSdkException
Link copied to clipboard
data object NoopLogger : Logger

Drop-everything logger. Default when no DI-injected impl is wired.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class NoOutputGeneratedError(message: String = "No output generated") : AiSdkException
Link copied to clipboard
class NoSpeechGeneratedError(message: String = "No speech generated", val responses: List<LanguageModelResponseMetadata> = emptyList(), cause: Throwable? = null) : AiSdkException
Link copied to clipboard
class NoSuchModelError(providerId: String?, modelType: String, modelId: String, message: String = buildString { append("No ") append(modelType) append(" model registered for `") providerId?.let { append(it).append(":") } append(modelId) append("`") }) : AiSdkException
Link copied to clipboard
class NoSuchProviderError(val providerId: String, val availableProviders: List<String> = emptyList()) : AiSdkException
Link copied to clipboard
class NoSuchToolError(val toolName: String, val availableTools: List<String>? = null, message: String = "Model tried to call unavailable tool '$toolName'. " + if (availableTools == null) { "No tools are available." } else { "Available tools: ${availableTools.joinToString(", ")}." }) : AiSdkException
Link copied to clipboard
class NoTranscriptGeneratedError(message: String = "No transcript generated", val responses: List<LanguageModelResponseMetadata> = emptyList(), cause: Throwable? = null) : AiSdkException
Link copied to clipboard
class NoVideoGeneratedError(message: String = "No video generated", val responses: List<LanguageModelResponseMetadata> = emptyList(), cause: Throwable? = null) : AiSdkException
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class OAuthProtectedResourceMetadata(val resource: String, val authorizationServers: List<String>? = null, val jwksUri: String? = null, val scopesSupported: List<String>? = null, val bearerMethodsSupported: List<String>? = null, val resourceName: String? = null)
Link copied to clipboard
class OAuthTokens(val accessToken: String, val tokenType: String, val idToken: String? = null, val expiresIn: Long? = null, val scope: String? = null, val refreshToken: String? = null)
Link copied to clipboard
sealed class Output<T>
Link copied to clipboard
sealed class ParseResult<out T>
Link copied to clipboard

Streaming-safe partial-JSON repair + parse operations. Grouped into an object so the helpers stay file-local members rather than loose top-level functions.

Link copied to clipboard
class PartialJsonResult(val value: JsonElement?, val state: PartialJsonState)

Result of PartialJson.parsePartialJson: value is non-null only on the two

Link copied to clipboard

Outcome of PartialJson.parsePartialJson, mirroring v6's four state strings.

Link copied to clipboard
class PendingApproval(val toolCallId: String, val toolName: String, val input: JsonElement, val approvalId: String? = null, val signature: String? = null)

A pending tool-call approval surfaced from Agent.generate / Agent.stream. Per v6 RPC semantics, generation completes when one or more tools require approval — the host inspects GenerateResult.pendingApprovals, presents UI, and resumes by calling Agent.generate again with messages = result.messages + ToolApprovalResponseMessage(...).

Link copied to clipboard
class PrepareCallScope<TContext>(val options: TContext?, val instructions: String, val model: LanguageModel, val tools: ToolSet<TContext>)

Scope for prepareCall, run once before the loop starts. Useful for RAG context injection, per-user customization, database lookups that shouldn't repeat per step.

Link copied to clipboard
class PrepareStepScope<TContext>(val stepNumber: Int, val model: LanguageModel, val steps: List<StepResult>, val messages: List<ModelMessage>, val context: TContext?)

Scope for prepareStep, run before every step in the loop. Used for: model routing per step (cheap model for step 1 + 2, expensive for step 3), tool gating per step (only the search tool is callable on step 1), dynamic system prompts, message compression.

Link copied to clipboard

Resolves a prompt for a specific model — the port of upstream's convertToLanguageModelPrompt. Grouped as object members because top-level loose functions are disallowed in this codebase; behavior is identical to the prior free-function form.

Link copied to clipboard
interface Provider
Link copied to clipboard
value class ProviderId(val value: String)
Link copied to clipboard
@Serializable(with = ProviderMetadataSerializer::class)
sealed class ProviderMetadata
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Typed, value-class- and ModelRef-aware accessors over Provider. These are member-extensions: callers reach them via member import or with(ProviderModels) { ... }.

Link copied to clipboard
sealed class ProviderOptions

Typed provider-options boundary (tenet T2).

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class ProviderRegistry(providers: Map<String, Provider>, defaultProviderId: String? = null, separator: String = ":", languageModelMiddleware: List<LanguageModelMiddleware> = emptyList()) : Provider
Link copied to clipboard
class ProviderToolFactory<TInput, TContext>(id: String, inputSerializer: KSerializer<TInput>, inputSchema: Schema<TInput>, defaultDescription: String = "Provider tool ")
Link copied to clipboard
class ProviderToolFactoryWithOutputSchema<TInput, TOutput, TContext>(id: String, inputSerializer: KSerializer<TInput>, inputSchema: Schema<TInput>, outputSerializer: KSerializer<TOutput>, outputSchema: Schema<TOutput>, supportsDeferredResults: Boolean = false, defaultDescription: String = "Provider tool ")
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
data class PruneToolCallRule(val type: PruneToolCallRuleType, val tools: Set<String>? = null)
Link copied to clipboard
Link copied to clipboard
sealed class PruneToolCalls
Link copied to clipboard
class ReadResourceResult(val contents: List<JsonObject>, val meta: JsonObject? = null)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
interface Redactor
Link copied to clipboard
class RerankedItem<T>(val value: T, val score: Float, val index: Int)
Link copied to clipboard
object Reranking
Link copied to clipboard
interface RerankingModel
Link copied to clipboard
class RerankingModelResult(val results: List<RerankedItem<String>>, val usage: Usage = Usage(), val warnings: List<CallWarning> = emptyList(), val response: LanguageModelResponseMetadata = LanguageModelResponseMetadata(), val providerMetadata: ProviderMetadata = ProviderMetadata.None)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class RerankResult<T>(val results: List<RerankedItem<T>>, val originalDocuments: List<T> = emptyList(), val usage: Usage = Usage(), val warnings: List<CallWarning> = emptyList(), val response: LanguageModelResponseMetadata = LanguageModelResponseMetadata(), val providerMetadata: ProviderMetadata = ProviderMetadata.None)
Link copied to clipboard
sealed interface ResponseFormat

Wire-level constraint on what shape the model is allowed to emit. Mirrors v6's responseFormat (per call-settings.ts:103-128 → historical parity gap #20). Distinct from Output — Output is the post-decode wrapper that turns text into typed values; ResponseFormat is what the provider sees at call time.

Link copied to clipboard
class RetryAttemptDetail(val attempt: Int, val error: Throwable, val retryable: Boolean, val delayMs: Long?)
Link copied to clipboard
fun interface RetryDelayGenerator
Link copied to clipboard
class RetryError(message: String, val reason: RetryErrorReason, val errors: List<Throwable>, val attempts: List<RetryAttemptDetail> = errors.mapIndexed { index, error -> RetryAttemptDetail( attempt = index, error = error, retryable = index < errors.lastIndex, delayMs = null, ) }) : AiSdkException
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class Schema<T>(val jsonSchema: JsonElement, val validate: (JsonElement) -> T? = null)
Link copied to clipboard
object Schemas
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
interface SpeechModel
Link copied to clipboard
class SpeechModelResult(val audio: GeneratedFile?, val warnings: List<CallWarning> = emptyList(), val response: LanguageModelResponseMetadata = LanguageModelResponseMetadata(), val providerMetadata: ProviderMetadata = ProviderMetadata.None)
Link copied to clipboard
class SseMCPTransport(client: HttpClient, url: String, headers: Map<String, String> = emptyMap(), authProvider: OAuthClientProvider? = null, engineContext: CoroutineContext = Dispatchers.Default) : MCPTransport
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Snapshot of one completed loop step — surfaced to AgentEvent.StepFinished and accumulated in the loop state for PrepareStepScope.steps.

Link copied to clipboard

Returned from prepareStep. Any non-null field overrides the agent default / prepareCall value for this step only.

Link copied to clipboard
Link copied to clipboard
fun interface StopCondition
Link copied to clipboard

Sealed event stream emitted by LanguageModel.stream and surfaced to application code via Agent.stream. Mirrors the v6 stream-part taxonomy (per packages/ai/src/generate-text/stream-text-result.ts in vercel/ai) adapted to Kotlin sealed classes for exhaustive when.

Link copied to clipboard
Link copied to clipboard
class StreamObjectFinish<TOutput>(val value: TOutput, val usage: Usage, val finishReason: FinishReason, val warnings: List<CallWarning>, val response: LanguageModelResponseMetadata)
Link copied to clipboard
Link copied to clipboard
class StreamTextResult(sourceStream: Flow<StreamEvent>, val request: LanguageModelRequestMetadata = LanguageModelRequestMetadata(), initialResponse: LanguageModelResponseMetadata = LanguageModelResponseMetadata())

Streaming generation result — memoised replay. A terminal upstream run is collected at most once; later collectors replay the captured events. If every collector leaves before the upstream reaches a terminal state, that producer is cancelled, its partial buffer is discarded, and a later collector starts a fresh upstream run. To preserve full replay for a collector that attaches after the first event, the result keeps the terminal stream event sequence in memory for the result lifetime. Hosts that need minimum peak memory for a guaranteed single-consumer path can collect the model stream directly instead of using this replaying result surface.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class StructuredObjectGenerator<RESULT>(model: LanguageModel, schema: Schema<RESULT>, config: CallConfig = CallConfig(), schemaName: String = "object", schemaDescription: String? = null)

Wires a LanguageModel to the structured-object machinery: constrains the model to emit JSON for schema, streams its text deltas into StructuredObject.phases (the shared parse/validate loop), and surfaces typed partials/value. Mirrors TextGenerator — a PascalCase class, not a camelCase top-level generateObject/streamObject.

Link copied to clipboard
Link copied to clipboard
sealed class StructuredObjectPhase<out RESULT>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
interface Telemetry
Link copied to clipboard
Link copied to clipboard
class TelemetryCall(val callId: String, val agentId: String, val agentVersion: String? = null, val modelId: String? = null, val functionId: String? = null)

Correlation envelope for one agent invocation (one generate/stream call). Every Telemetry event of that invocation carries the same callId, so an integration can reconstruct per-call traces even when a single agent instance serves concurrent calls. agentId/agentVersion mirror Agent.id/Agent.version (parity gap #33: "useful for telemetry"); functionId comes from TelemetrySettings.functionId.

Link copied to clipboard
class TelemetryRegistry(seed: List<Telemetry> = emptyList())

Ordered registry of Telemetry integrations, keyed by Telemetry.name (re-register replaces, keeping the original position).

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
sealed class TelemetrySpanStatus
Link copied to clipboard
interface TelemetryTracer
Link copied to clipboard
Link copied to clipboard
class TextGenerator @JvmOverloads constructor(model: LanguageModel, config: CallConfig = CallConfig())

High-level text generation facade for a single LanguageModel.

Link copied to clipboard
abstract class Tool<TInput, TOutput, TContext>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class ToolCallNotFoundForApprovalError(val toolCallId: String, val approvalId: String) : AiSdkException
Link copied to clipboard
class ToolCallRepairError(val originalError: Throwable, cause: Throwable, message: String = "Error repairing tool call: ") : AiSdkException
Link copied to clipboard
typealias ToolCallRepairFunction<TContext> = suspend (failedCall: ContentPart.ToolCall, error: Throwable, messages: List<ModelMessage>, tools: ToolSet<TContext>) -> ContentPart.ToolCall?

Callback invoked when a tool call's JSON arguments fail to decode. Return a corrected ContentPart.ToolCall to retry, or null to give up. Mirrors v6's experimental_repairToolCall.

Link copied to clipboard

Whether the LLM should call a tool, no tool, a specific tool, etc.

Link copied to clipboard
class ToolExecutionContext<TContext>(val context: TContext?, val abortSignal: AbortSignal, val stepNumber: Int, val messages: List<ModelMessage>, val toolCallId: String, val writer: ToolStreamWriter = NoopToolStreamWriter)

What Tool.execute receives as its context. Holds the typed application context, abort signal, step number, running message list, and a writer for custom events.

Link copied to clipboard

Resource limits for executing tool calls emitted by one agent step.

Link copied to clipboard
abstract class ToolLoopAgent<TContext, TOutput>(settings: AgentSettings<TContext> = AgentSettings(), val model: LanguageModel = settings.model ?: throw InvalidArgumentError("model", "ToolLoopAgent requires model via parameter or settings"), val instructions: String = settings.instructions ?: throw InvalidArgumentError( "instructions", "ToolLoopAgent requires instructions via parameter or settings", ), val tools: ToolSet<TContext> = settings.tools ?: throw InvalidArgumentError("tools", "ToolLoopAgent requires tools via parameter or settings"), val output: Output<TOutput>? = settings.output as Output<TOutput>?, val stopWhen: StopCondition = settings.stopWhen ?: StepCountIs(20)) : Agent<TContext, TOutput>

Abstract base Agent implementation — the canonical v6 ToolLoopAgent. Extend it; do not instantiate it. A concrete agent subclasses this (e.g. class MyAgent(...) : ToolLoopAgent<C, O>(...)) so the agent's identity, tools, lifecycle overrides, and DI live in one named type — never a bare ToolLoopAgent(...) held as a field.

Link copied to clipboard
sealed class ToolLoopAgentAction<out TContext>

Actions the host dispatches to drive the agent. Mirrors the Action sealed type a Compose ViewModel exposes — the agent is the "model" of an MVI loop.

Link copied to clipboard
data class ToolLoopAgentState(val messages: List<ModelMessage> = emptyList(), val streamingAssistantText: String = "", val currentToolCalls: List<ContentPart.ToolCall> = emptyList(), val pendingApprovals: List<PendingApproval> = emptyList(), val phase: ToolLoopAgentState.Phase = Phase.Idle, val totalSteps: Int = 0, val lastFinishReason: FinishReason? = null)
Link copied to clipboard
Link copied to clipboard
data class ToolNameMapping(customToolNameToProviderToolName: Map<String, String>, providerToolNameToCustomToolName: Map<String, String>)
Link copied to clipboard

Options bag passed to predicate callbacks (Tool.needsApproval, Tool.toModelOutput).

Link copied to clipboard
sealed class ToolResult<out O>

Wrapper emitted by Tool.execute — currently only Success; sealed for future variants.

Link copied to clipboard

Structured return type for Tool.toModelOutput.

Link copied to clipboard
Link copied to clipboard
class ToolSchema(val name: String, val description: String, val strict: Boolean? = null, val inputExamples: List<String> = emptyList(), val metadata: Map<String, JsonElement> = emptyMap(), val providerExecuted: Boolean = false, val providerOptions: ProviderOptions = ProviderOptions.None)

LLM-visible metadata for a Tool. Separates schema from executor.

Link copied to clipboard

Bundles selected ToolSchema flags for factory functions.

Link copied to clipboard
Link copied to clipboard
class ToolSet<TContext>(val byName: Map<String, Tool<*, *, TContext>>)

Erased map of tools indexed by name. Application code constructs via the ToolSet factory.

Link copied to clipboard
Link copied to clipboard

Lets a tool's executor write custom events into the agent's active output stream. Distinct from the streaming-tool mechanism — pushes arbitrary StreamEvents.

Link copied to clipboard
class TooManyEmbeddingValuesForCallError(val provider: String, val modelId: String, val maxEmbeddingsPerCall: Int, val values: List<Any?>) : AiSdkException
Link copied to clipboard
class TranscribeResult(val text: String, val segments: List<TranscriptSegment> = emptyList(), val warnings: List<CallWarning> = emptyList(), val response: LanguageModelResponseMetadata = LanguageModelResponseMetadata(), val providerMetadata: ProviderMetadata = ProviderMetadata.None, val responses: List<LanguageModelResponseMetadata> = listOf(response), val language: String? = null, val durationInSeconds: Float? = null)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
class TranscriptionModelResult(val text: String?, val segments: List<TranscriptSegment> = emptyList(), val warnings: List<CallWarning> = emptyList(), val response: LanguageModelResponseMetadata = LanguageModelResponseMetadata(), val providerMetadata: ProviderMetadata = ProviderMetadata.None, val language: String? = null, val durationInSeconds: Float? = null)
Link copied to clipboard
Link copied to clipboard
class TranscriptSegment(val text: String, val startSeconds: Float? = null, val endSeconds: Float? = null)
Link copied to clipboard
class TypeValidationContext(val field: String? = null, val entityName: String? = null, val entityId: String? = null)
Link copied to clipboard
class TypeValidationError(val value: JsonElement?, cause: Throwable, val context: TypeValidationContext? = null) : AiSdkException
Link copied to clipboard
class UiMessageStreamError(message: String, cause: Throwable? = null) : AiSdkException
Link copied to clipboard
class UnauthorizedError(message: String = "Unauthorized") : AiSdkException
Link copied to clipboard
class UnsupportedFunctionalityError(val functionality: String, message: String = "'") : AiSdkException
Link copied to clipboard
Link copied to clipboard
class Usage(val inputTokens: Usage.InputTokenBreakdown = InputTokenBreakdown(), val outputTokens: Usage.OutputTokenBreakdown = OutputTokenBreakdown(), val raw: JsonElement? = null)

Token-usage tracking, surfaced on completed steps and final results. Per historical parity gap #19, the shape mirrors v6's rich tree — input tokens split into noCache / cacheRead / cacheWrite and output tokens split into text / reasoning plus a raw slot for provider-specific payloads.

Link copied to clipboard

Arithmetic over Usage. The + operator lives here as a member-extension (decision-C: no loose top-level funs). Call sites bring it into scope with with(UsageArithmetic) { a + b } or a member import.

Link copied to clipboard
Link copied to clipboard
sealed class ValidationResult<out T>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
interface VideoModel
Link copied to clipboard
class VideoModelResult(val videos: List<GeneratedFile>, val warnings: List<CallWarning> = emptyList(), val response: LanguageModelResponseMetadata = LanguageModelResponseMetadata(), val providerMetadata: ProviderMetadata = ProviderMetadata.None)
Link copied to clipboard
class WireDecodeException(val provider: String, val operation: String, val path: String, message: String, val value: JsonElement? = null, cause: Throwable? = null) : AiSdkException

Properties

Link copied to clipboard

A signal that is never aborted. Useful as a default.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Global registry — upstream v7 registerTelemetry: register once at startup, all calls emit.

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard

Bind an abort signal to a Job so the signal fires when the job completes (cancelled or otherwise). Lets a parent scope's lifetime automatically cancel anything observing the signal.

Link copied to clipboard
Link copied to clipboard
fun AllOf(vararg conditions: StopCondition): StopCondition

Stop only when all conditions report done.

Link copied to clipboard
fun AnyOf(vararg conditions: StopCondition): StopCondition

Stop when any of conditions reports done. v6's array-of-conditions shape.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun CreateGatewayHttpProvider(client: HttpClient, settings: GatewayProviderSettings = GatewayProviderSettings(), json: Json = aiSdkJson): GatewayProvider
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun DefaultEmbeddingSettingsMiddleware(maxEmbeddingsPerCall: Int? = null, truncate: Boolean? = null, providerOptions: ProviderOptions = ProviderOptions.None, headers: Map<String, String> = emptyMap()): EmbeddingModelMiddleware
Link copied to clipboard
fun DevToolsMiddleware(recorder: DevToolsRecorder = InMemoryDevToolsRecorder(), environment: String = "development", runId: String = IdGenerator.generate(prefix = "run"), idGenerator: () -> String = { IdGenerator.generate(prefix = "step") }): LanguageModelMiddleware
Link copied to clipboard
fun <TContext> DynamicTool(name: String, description: String, inputSchemaJson: String = "{}", metadata: Map<String, JsonElement> = emptyMap(), toModelOutput: (JsonElement, ToolPredicateOptions<TContext>) -> ToolResultOutput? = null, executor: suspend ToolExecutionContext<TContext>.(JsonElement) -> JsonElement): Tool<JsonElement, JsonElement, TContext>

Runtime-typed tool — inputs and outputs are raw JsonElement. Schema is supplied as a JSON string and stored in ToolSchema.metadata under "inputSchema".

Link copied to clipboard

Execute a tool outside the agent loop with one-step lookahead semantics.

Link copied to clipboard
fun Gateway(settings: GatewayProviderSettings = GatewayProviderSettings()): GatewayProvider

Creates a Vercel AI Gateway provider.

Link copied to clipboard
fun GatewayProvider(settings: GatewayProviderSettings = GatewayProviderSettings()): GatewayProvider
Link copied to clipboard
fun GeneratedFile(data: FileData, mediaType: String = data.mediaType ?: "application/octet-stream", filename: String? = data.filename, providerMetadata: ProviderMetadata = ProviderMetadata.None): GeneratedFile
Link copied to clipboard

Stop the moment the named tool is called in any step.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun ModelRef(value: String): ModelRef
fun ModelRef(providerId: ProviderId, modelId: ModelId): ModelRef
fun ModelRef(providerId: String, modelId: String): ModelRef
Link copied to clipboard

Stock self-healing repair: re-prompt the model with the tool's JSON schema + the failed args + the parse error, asking for corrected JSON. If the second response parses cleanly, return a ContentPart.ToolCall with the corrected input; otherwise return null (the agent loop surfaces StreamEvent.ToolError).

Link copied to clipboard
fun <T> OutputArray(elementSerializer: KSerializer<T>, name: String = elementSerializer.descriptor.serialName.substringAfterLast('.') + "[]", description: String? = null): Output<List<T>>
Link copied to clipboard
fun OutputChoice(options: Iterable<String>, name: String = "choice", description: String? = null): Output<String>
fun OutputChoice(vararg options: String, name: String = "choice", description: String? = null): Output<String>
fun <T> OutputChoice(options: Iterable<T>, encode: (T) -> String, decodeChoice: (String) -> T, name: String = "choice", description: String? = null): Output<T>
Link copied to clipboard
fun OutputJson(name: String = "json", description: String? = null): Output<JsonElement>
Link copied to clipboard
fun <T> OutputObj(serializer: KSerializer<T>, name: String = serializer.descriptor.serialName.substringAfterLast('.'), description: String? = null): Output<T>
Link copied to clipboard
fun Provider(providerId: String, languageModels: Map<String, LanguageModel> = emptyMap(), embeddingModels: Map<String, EmbeddingModel> = emptyMap(), imageModels: Map<String, ImageModel> = emptyMap(), speechModels: Map<String, SpeechModel> = emptyMap(), transcriptionModels: Map<String, TranscriptionModel> = emptyMap(), rerankingModels: Map<String, RerankingModel> = emptyMap(), videoModels: Map<String, VideoModel> = emptyMap(), fallbackProvider: Provider? = null): Provider
Link copied to clipboard
fun <TInput, TOutput, TContext> ProviderExecutedTool(name: String, description: String, inputSerializer: KSerializer<TInput>, outputSerializer: KSerializer<TOutput>, metadata: Map<String, JsonElement> = emptyMap()): Tool<TInput, TOutput, TContext>

Provider-executed tool: advertises itself to the model but has no local executor.

Link copied to clipboard
Link copied to clipboard

Stop when the model has emitted the same (toolName, input) tuple n consecutive steps in a row — i.e. the loop is spinning on a tool whose result didn't change the model's behavior. Documented anti-pattern for small / on-device models that can't reason their way out of an unhelpful tool result; surfaced as a hard stop so the host renders the trapped state instead of looping until the step cap.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun <T> SimulateReadableStream(chunks: Iterable<T>, delayMillis: Long = 0): Flow<T>

Creates a cold Flow that emits chunks in order with delayMillis between chunks. The first chunk is emitted immediately; the delay applies only between consecutive chunks.

Link copied to clipboard
fun SmoothStream(upstream: Flow<StreamEvent>, delayMs: Long = 10, chunkBy: ChunkBy = ChunkBy.Word): Flow<StreamEvent>
Link copied to clipboard
Link copied to clipboard

Stop after n completed steps. v6's default is 20 if stopWhen omitted.

Link copied to clipboard
Link copied to clipboard
inline fun <TInput, TOutput, TContext> StreamingTool(name: String, description: String, noinline needsApproval: suspend (input: TInput, options: ToolPredicateOptions<TContext>) -> Boolean? = null, noinline toModelOutput: (TOutput, ToolPredicateOptions<TContext>) -> ToolResultOutput? = null, schemaOptions: ToolSchemaOptions = ToolSchemaOptions {}, inputExamples: List<String> = emptyList(), noinline onInputStart: suspend (streamingId: String) -> Unit? = null, noinline onInputDelta: suspend (streamingId: String, delta: String) -> Unit? = null, noinline onInputAvailable: suspend (toolCallId: String, input: TInput) -> Unit? = null, metadata: Map<String, JsonElement> = emptyMap(), providerOptions: ProviderOptions = ProviderOptions.None, noinline executor: ToolExecutionContext<TContext>.(TInput) -> Flow<TOutput>): Tool<TInput, TOutput, TContext>

Reified streaming factory — infers serializers from type parameters.

fun <TInput, TOutput, TContext> StreamingTool(name: String, description: String, inputSerializer: KSerializer<TInput>, outputSerializer: KSerializer<TOutput>, needsApproval: suspend (input: TInput, options: ToolPredicateOptions<TContext>) -> Boolean? = null, toModelOutput: (TOutput, ToolPredicateOptions<TContext>) -> ToolResultOutput? = null, schemaOptions: ToolSchemaOptions = ToolSchemaOptions {}, inputExamples: List<String> = emptyList(), onInputStart: suspend (streamingId: String) -> Unit? = null, onInputDelta: suspend (streamingId: String, delta: String) -> Unit? = null, onInputAvailable: suspend (toolCallId: String, input: TInput) -> Unit? = null, metadata: Map<String, JsonElement> = emptyMap(), providerOptions: ProviderOptions = ProviderOptions.None, executor: ToolExecutionContext<TContext>.(TInput) -> Flow<TOutput>): Tool<TInput, TOutput, TContext>

Streaming Tool factory — executor returns Flow, each emission is a value.

Link copied to clipboard
fun <TOutput> StreamObjectResult(model: LanguageModel, output: Output<TOutput>, prompt: String? = null, messages: List<ModelMessage> = emptyList(), system: String? = null, temperature: Float? = null, topP: Float? = null, topK: Int? = null, maxOutputTokens: Int? = null, stopSequences: List<String> = emptyList(), seed: Int? = null, providerOptions: ProviderOptions = ProviderOptions.None, abortSignal: AbortSignal = AbortSignalNever, presencePenalty: Float? = null, frequencyPenalty: Float? = null, responseFormat: ResponseFormat = ResponseFormat.Text, repairText: (String) -> String?? = null): StreamObjectResult<TOutput>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
inline fun <TInput, TOutput, TContext> Tool(name: String, description: String, noinline needsApproval: suspend (input: TInput, options: ToolPredicateOptions<TContext>) -> Boolean? = null, noinline toModelOutput: (TOutput, ToolPredicateOptions<TContext>) -> ToolResultOutput? = null, schemaOptions: ToolSchemaOptions = ToolSchemaOptions {}, inputExamples: List<String> = emptyList(), noinline onInputStart: suspend (streamingId: String) -> Unit? = null, noinline onInputDelta: suspend (streamingId: String, delta: String) -> Unit? = null, noinline onInputAvailable: suspend (toolCallId: String, input: TInput) -> Unit? = null, metadata: Map<String, JsonElement> = emptyMap(), providerOptions: ProviderOptions = ProviderOptions.None, noinline executor: suspend ToolExecutionContext<TContext>.(TInput) -> TOutput): Tool<TInput, TOutput, TContext>

Reified convenience overload — infers serializers from type parameters.

fun <TInput, TOutput, TContext> Tool(name: String, description: String, inputSerializer: KSerializer<TInput>, outputSerializer: KSerializer<TOutput>, needsApproval: suspend (input: TInput, options: ToolPredicateOptions<TContext>) -> Boolean? = null, toModelOutput: (TOutput, ToolPredicateOptions<TContext>) -> ToolResultOutput? = null, schemaOptions: ToolSchemaOptions = ToolSchemaOptions {}, inputExamples: List<String> = emptyList(), onInputStart: suspend (streamingId: String) -> Unit? = null, onInputDelta: suspend (streamingId: String, delta: String) -> Unit? = null, onInputAvailable: suspend (toolCallId: String, input: TInput) -> Unit? = null, metadata: Map<String, JsonElement> = emptyMap(), providerOptions: ProviderOptions = ProviderOptions.None, executor: suspend ToolExecutionContext<TContext>.(TInput) -> TOutput): Tool<TInput, TOutput, TContext>

Single-value Tool factory — executor is a suspend function returning TOutput.

Link copied to clipboard
fun ToolApprovalResponseMessage(toolCallId: String, approved: Boolean, reason: String? = null, approvalId: String? = null): ModelMessage
Link copied to clipboard
fun ToolMessage(toolCallId: String, toolName: String, output: JsonElement): ModelMessage
Link copied to clipboard
fun ToolNameMapping(tools: List<LanguageModelTool> = emptyList(), providerToolNames: Map<String, String>, resolveProviderToolName: (LanguageModelTool) -> String?? = null): ToolNameMapping
Link copied to clipboard
Link copied to clipboard
fun <TContext> ToolSet(vararg tools: Tool<*, *, TContext>): ToolSet<TContext>

Construct a ToolSet from individual tools. Throws on duplicate names.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Compose middlewares over model into a new LanguageModel. Order: the first middleware in the list is the outermost wrapper — wrapGenerate runs first on the way in, last on the way out (innermost in the call stack, like Express middleware).

Link copied to clipboard
fun WrapProvider(provider: Provider, middleware: ProviderMiddleware): Provider